package com.fancy.learncenter.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.fancy.learncenter.common.MyApplication;

public class SPUtils {
    private final static String PREFERENCE_NAME = "superservice_ly";

    private static String isFirst_key = "isFirst";

    private static String isSearchRecord_key = "isSearchRecord";

    /**
     * 是否第一次安装
     *
     * @param value true 更新数据
     * @return
     */
    public static boolean first(boolean value) {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean(isFirst_key, value);
        return editor.commit();
    }

    public static boolean isFirst() {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);

        if (settings.getBoolean(isFirst_key, true)) {
            return true;
        } else {
            return false;
        }
    }


    /**
     * 搜索记录
     *
     * @param value
     * @return
     */
    public static boolean putSearchRecord(String value) {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString(isSearchRecord_key, value);
        return editor.commit();
    }

    /**
     * 获取搜索记录
     *
     * @return
     */
    public static String getSearchRecord() {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        return settings.getString(isSearchRecord_key, "");
    }

    /**
     * 设置默认班级ID
     *
     * @param value
     * @return
     */
    public static boolean putClassID(String value) {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("classId", value);
        return editor.commit();
    }

    /**
     * 获取默认班级ID
     * 字符串形式  classID+","+className
     *
     * @return
     */
    public static String getClassID() {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        return settings.getString("classId", "");
    }


    /**
     * @param value
     * @return
     */
    public static void putToken(String value) {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("token", value);
        editor.commit();
    }

    /**
     * @return
     */
    public static String getToken() {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        return settings.getString("token", "");
    }

    /**
     * @param value
     * @return
     */
    public static void putUserID(String value) {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("user_id", value);
        editor.commit();
    }

    /**
     * @return
     */
    public static String getUserID() {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        return settings.getString("user_id", "");
    }

    /**
     * @param value
     * @return
     */
    public static void putUserIcon(String value) {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("user_icon", value);
        editor.commit();
    }

    /**
     * @return
     */
    public static String getUserIcon() {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        return settings.getString("user_icon", "");
    }

    /**
     * @param value
     * @return
     */
    public static void putUserName(String value) {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("user_name", value);
        editor.commit();
    }

    /**
     * @return
     */
    public static String getUserName() {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        return settings.getString("user_name", "");
    }

    /**
     * @param value
     * @return
     */
    public static void putUserMobile(String value) {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("user_mobile", value);
        editor.commit();
    }

    /**
     * @return
     */
    public static String getUserMobile() {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        return settings.getString("user_mobile", "");
    }

    /**
     * @param value
     * @return
     */
    public static void putUserSign(String value) {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("user_sign", value);
        editor.commit();
    }

    /**
     * @return
     */
    public static String getUserSign() {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        return settings.getString("user_sign", "");
    }

    /**
     * @param value
     * @return
     */
    public static void putUserAge(String value) {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("user_age", value);
        editor.commit();
    }

    /**
     * @return
     */
    public static String getUserAge() {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        return settings.getString("user_age", "");
    }

    /**
     * @param value
     * @return
     */
    public static void putUserSex(String value) {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("user_sex", value);
        editor.commit();
    }

    /**
     * @return
     *
     * :1男,2女
     */
    public static String getUserSex() {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        return settings.getString("user_sex", "");
    }

    /**
     * @param value
     * @return
     */
    public static void putUserBirthday(String value) {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("user_birthday", value);
        editor.commit();
    }

    /**
     * @return
     */
    public static String getUserBirthday() {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        return settings.getString("user_birthday", "");
    }
}